<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>作用域插槽</title>
    <style>
        .active {
            color: red;
        }
    </style>
</head>

<body>
    <div class="app">
        <hello-vue :list="heroList">
            <template slot-scope="heroData">
                <span :class="heroData.hero.id === 1 ? 'active' : ''">{{heroData.hero.name}}</span>
            </template>
        </hello-vue>
    </div>

    <script src="./js/vue.js"></script>
    <script>
        Vue.component('hello-vue', {
            props: ['list'],
            template: `
            <div>
                <p v-for="item in list" :key="item.id">
                    <slot :hero='item'>{{item.name}}</slot>
                </p>
            </div>
            `
        })
        var xm = new Vue({
            el: '.app',
            data: {
                heroList: [
                    {
                        id: 1,
                        name: '貂蝉'
                    },
                    {
                        id: 2,
                        name: '刘备'
                    },
                    {
                        id: 3,
                        name: '吕布'
                    },

                ]

            }
        })



    </script>

</body>

</html>